package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.StatsDeviceService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.StatsCommodityStockRecordDto;
import com.huilian.iotbox.data.dto.StatsDeviceDto;
import com.huilian.iotbox.data.vo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.ExecutionException;

/**
 * @author 龙 路 飞
 * @CreateDate: 2021-09-23 16:23
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/api/statsDevice")
public class StatsDeviceController extends UserInfoController {
    @Autowired
    private StatsDeviceService statsDeviceService;



    @PostMapping("/findStatsStoreDeviceByApplet")
    public ServerResponse findStatsStoreDeviceByApplet(@RequestBody StatsDeviceDto statsDeviceDto, HttpServletRequest request) throws ExecutionException, InterruptedException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsDeviceDto.setUserInfo(userInfo);
        return statsDeviceService.findStatsStoreDeviceByApplet(statsDeviceDto);
    }
    /**
     * 设备分析-小程序端
     *
     * @param statsDeviceDto
     * @param request
     * @return
     */
    @GetMapping("/findAllSumStatsDeviceSumByApplet")
    public ServerResponse findAllSumStatsDeviceSumByApplet(StatsDeviceDto statsDeviceDto, HttpServletRequest request) throws ExecutionException, InterruptedException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsDeviceDto.setUserInfo(userInfo);
        return statsDeviceService.findAllSumStatsDeviceSumByApplet(statsDeviceDto);
    }

    /**
     * 查询设备统计,用来展示在table表格里面
     */
    @PostMapping("/findStatsDeviceTableList")
    public ServerResponse findStatsDeviceTableList(@RequestBody StatsDeviceDto statsDeviceDto, HttpServletRequest request){
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsDeviceDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(statsDeviceService.findStatsDeviceTableList(statsDeviceDto));
    }

    /**
     * 查询售货机设备统计,用来展示在table表格里面
     */
    @PostMapping("/findStatsSalesDeviceTableList")
    public ServerResponse findStatsSalesDeviceTableList(@RequestBody StatsDeviceDto statsDeviceDto, HttpServletRequest request){
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsDeviceDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(statsDeviceService.findStatsSalesDeviceTableList(statsDeviceDto));
    }
}
